﻿using System;
using System.Collections.Generic;
using System.Text;

namespace KnBinarySerializer.Group
{
    internal class ByteArrayFormatter : IFormatter
    {
        public Type GetHandleType()
        {
            return typeof(byte[]);
        }

        public byte GetKey()
        {
            return 41;
        }
        public bool IsFixLen()
        {
            return false;
        }
        public object ReadBytes(BinarySerializeManager content, int maxLen, Type type)
        {
            maxLen = content.ReadInt();//先要读取长度
            return content.ReadBytes(maxLen);
        }

        public int WriteBytes(BinarySerializeManager serial, object obj)
        {
            byte[] bytes = (byte[])obj;
            serial.Write(bytes.Length);
            serial.Write(bytes);
            return bytes.Length;
        }
    }
}
